import java.util.HashMap;
import java.util.Map;

/**
 * Created by forcht on 2018/5/2.
 * 穷举...要考虑到特殊情况，斜率不存在、点重合、HashMap里-0.0和0.0是不同的key...
 */
public class Solution {
    public int maxPoints(Point[] points) {
        if(points.length==0)return 0;
        if (points.length==1)return 1;
        int sum=0;
        for(int i=0;i<points.length;i++){
            int max=1;
            int dup=0;
            int cnt=0;
            Map<Double,Integer> map=new HashMap<>();
            for(int j=i+1;j<points.length;j++){
                if(i!=j){
                    double x=points[i].x-points[j].x;
                    double y=points[i].y-points[j].y;
                    //判断是否重合
                    if(x==0&&y==0){
                         dup++;
                    }
                    //判断是否垂直
                    else if (x==0){
                        if(cnt==0)cnt=2;
                        else cnt++;
                        max=Math.max(max,cnt);
                    }else {
                        double k=y/x;
                        if(map.containsKey(k))map.put(k,map.get(k)+1);
                        else map.put(k,2);
                        max=Math.max(max,map.get(k));
                    }
                }
            }
            sum=Math.max(max+dup,sum);
        }
        return sum;
    }

    public static void main(String[] args) {
        Point p1=new Point(2,3);
        Point p2=new Point(3,3);
        Point p3=new Point(-5,3);
        Point[] points={p1,p2,p3};
        Solution solution=new Solution();
        System.out.println(solution.maxPoints(points));
    }
}

class Point {
    int x;
    int y;

    Point() {
        x = 0;
        y = 0;
    }

    Point(int a, int b) {
        x = a;
        y = b;
    }
}


